<?php

/*
	Title: message_count

	About: Author
		Jaybill McCarthy

	About: License
		<http://communit.as/docs/license>

	Function: smarty_function_new_messages
		Returns the number of messages of a given type for a given username

	Arguments:
		$params - An array of variables.
		&$smarty - TBD

	Params:
		username (string) - Username to check for new messages
		type (optional string) -  new|total|sent - defaults to new

	Returns:
		The number of messages

		Execution Example:
		(begin example)
			<!-- as used in a Smarty view template -->
			{if $module_mail}
				{t}You have{/t} {message_count username="jaybill"} {t}new messages.{/t}
			{/if}
		(end example)
*/
function smarty_function_message_count($params, &$smarty) {
	$out = 0;
	try {
		$mail_table = new MailMessages();		
		switch ($params['type']) {
			case "total":				
				$out = (int)$mail_table->getAllMailByUsername($params['username']);
				break;
			case "sent":
				$out = (int)$mail_table->getSentMailByUsername($params['username']);
				break;
			default:
				$out = (int)$mail_table->getNewMailByUsername($params['username']);
				break;
		}
	} catch (Exception $e) {
		$out = 0;
	} 
	return $out;
}
